package event

import (
	"fmt"
	"sync"
)

var defaultPluginMap map[string]func() EventProcessor
var defaultPluginMapLock sync.Mutex

func registerDefaultPlugin(name string, p func() EventProcessor) error {
	defaultPluginMapLock.Lock()
	defer defaultPluginMapLock.Unlock()
	if defaultPluginMap == nil {
		defaultPluginMap = make(map[string]func() EventProcessor)
	}
	if _, exists := defaultPluginMap[name]; exists {
		return fmt.Errorf("default plugin %s already exists", name)
	}
	defaultPluginMap[name] = p
	return nil
}
func getDefaultPlugin(name string) (EventProcessor, error) {
	defaultPluginMapLock.Lock()
	defer defaultPluginMapLock.Unlock()
	p, exists := defaultPluginMap[name]
	if !exists {
		return nil, fmt.Errorf("default plugin %s not found", name)
	}
	return p(), nil
}
